home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / Source / GENetReleaseƒ / Extras / Paths.c < prev    next >
Text File  |  1994-02-18  |  2KB  |  86 lines

  1. /*
  2.     Paths.c
  3.     
  4.     Paths routines for Graphic Elements
  5.     
  6.     Copyright 1993 by Al Evans
  7.     
  8.     11/10/93
  9.     
  10. */
  11.  
  12. #include "Paths.h"
  13.  
  14. void InitPath(PathRecPtr path)
  15. {
  16.     path->currStep = 0;
  17.     path->currFrame = 0;
  18.     path->currXMove = 0;
  19.     path->currYMove = 0;
  20.     path->count = 0;
  21.     path->sp = 0;
  22. }
  23.  
  24. void GetNextStep(PathRecPtr pathRec)
  25. {
  26.     PathEntryPtr    thisStep;
  27.     
  28.     thisStep = pathRec->path + pathRec->currStep;
  29.     if (pathRec->count > 0) {
  30.         pathRec->currXMove += thisStep->xVal;
  31.         pathRec->currYMove += thisStep->yVal;
  32.         pathRec->currFrame = 0;            //Any frame change has already been done
  33.         pathRec->count--;
  34.         return;
  35.     }
  36.     //Do path control command(s)
  37.     while (thisStep->command < 0) {
  38.         switch (thisStep->command) {
  39.             case repeatCmd:
  40.                 pathRec->count = thisStep->param;
  41.                 pathRec->currStep++;
  42.                 break;
  43.             case goToCmd:
  44.                 pathRec->currStep = thisStep->param;
  45.                 break;
  46.             case goSubCmd:
  47.                 pathRec->stack[pathRec->sp++] = pathRec->currStep;
  48.                 pathRec->currStep = thisStep->param;
  49.                 break;
  50.             case returnCmd:
  51.                 pathRec->currStep = pathRec->stack[--pathRec->sp] + 1;
  52.                 break;
  53.             case resetCmd:
  54.                 pathRec->currStep = 0;
  55.                 break;
  56.         }
  57.         thisStep = pathRec->path + pathRec->currStep;
  58.     }
  59.     switch (thisStep->command) {
  60.         case absMotionCmd:
  61.             pathRec->currXMove = thisStep->xVal;
  62.             pathRec->currYMove = thisStep->yVal;
  63.             break;
  64.         case relMotionCmd:
  65.             pathRec->currXMove += thisStep->xVal;
  66.             pathRec->currYMove += thisStep->yVal;
  67.             break;
  68.     }
  69.     pathRec->currFrame = thisStep->param;
  70.     if (pathRec->count)
  71.         pathRec->count--;
  72.     else
  73.         pathRec->currStep++;
  74. }
  75.  
  76. void DoPathGoTo(PathRecPtr path, short gotoStep)
  77. {
  78.     path->currStep = gotoStep;
  79. }
  80.  
  81. void DoPathGoSub(PathRecPtr path, short subRtnStep)
  82. {
  83.     path->stack[path->sp++] = path->currStep;
  84.     path->currStep = subRtnStep;
  85. }
  86.